package com.lingo.a2b.model.bo;

import com.lingo.a2b.model.vo.FieldInfoVo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author lingo
 * @date 2020/5/21 15:50
 * @Company: www.xyb2b.com
 */
@Getter
@Setter
public class FieldInfo {

    private String locateClassName;

    private boolean fisCollection;

    private String name;

    private String dbName;

    private String targetName;

    private Integer fvalueConverterId;

    private String meaning;

    private Boolean enable;

    private ClassInfo fieldClassInfo;

    public FieldInfo(String locateClassName, String name, String dbName, String meaning) {
        this.locateClassName = locateClassName;
        this.name = name;
        this.dbName = dbName;
        this.meaning = meaning;
    }

    public FieldInfo() {
    }

    public FieldInfoVo toVo(int fprojectId) {
        FieldInfoVo vo = new FieldInfoVo();
        vo.setFisCollection(this.fisCollection);
        vo.setMeaning(this.meaning);
        vo.setName(this.name);
        vo.setFsrcFieldName(dbName);
        vo.setFtargetFieldName(this.targetName);
        vo.setFprojectId(fprojectId);
        vo.setFenable(this.enable);
        vo.setFlocateClassName(this.locateClassName);
        vo.setFvalueConverterId(this.fvalueConverterId);
        if (!Objects.isNull(this.getFieldClassInfo()) && !CollectionUtils.isEmpty(this.getFieldClassInfo().getFieldInfoList())) {
            vo.setSonClassFieldList(this.getFieldClassInfo().getFieldInfoList().stream().map(fieldInfo -> fieldInfo.toVo(fprojectId)).collect(Collectors.toList()));
        }
        return vo;
    }
}
